<?php
defined('BASEPATH') OR exit ('No direct script access allowed');

require (APPPATH . '/libraries/REST_Controller.php');
include_once 'db_functions_music.php';
class playlist extends REST_Controller {

	function user_get() {
		echo "only support method post";

	}

	function savecontrol_post() {
		// get account from client with post method;
		$id = $this->post('id');
		$playlist = $this->post('playlist');
		$code_control = $this->post('code_control');
		$type = $this->post('type');
		$value = $this->post('value');
		$device = $this->post('device');
		$code = null;
		$result = null;

		$db = new db_functions_music();

		$isAddSucess = $db->saveControl($id, $code_control, $type, $value,$device);

		if (!$isAddSucess) {
			$code = -1;
			$result = "Network error!";

		} else {

			$code = 0;
			$result = "Success!";

		}

		$re = array (
			'code' => $code,
			'result' => $result,
			'data' => $isAddSucess,

			
		);

		$this->response($re);

	}

	function getcontrol_post() {
		$id = $this->post('id');
		$code = null;
		$result = null;
		$result = null;
		$db = new db_functions_music();
		$device = $this->post('device');

		$relPlaylist = $db->getControl($id,$device);

		if ($relPlaylist == null) {
			$code = -1;
			$result = "No data";

		} else {

			$code = 0;
			$result = "Success!";

		}

		$re = array (
			'code' => $code,
			'result' => $result,
			'data' => $relPlaylist,

			
		);
		
		if(strcmp($device, DEVICE_OTHER) == 0){
			
			
			
			$re = array (
			'code' => $code,
			'result' => $result,
			'data' => json_encode($relPlaylist),

			
		);
			
		}

		$this->response($re);
	}

}
?>
